#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vi: ts=4 expandtab
#
# Copyright (C) 2012 KT
#
# Author: Choonho Son <choonho.son@kt.com>
#

import subprocess
import os
import os.path
import socket


__version__="1.0"

def checkConnection(params):
	"""
	check TCP connection
	
	@params (dictionary)
	ip : destination IP address
	port : TCP port
	
	@return : True/False
	"""
	p = params
	HOST = p['ip']
	PORT = int(p['port'])
	s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	
	try:
		s.connect( (HOST, PORT) )
		s.close()
		return True
	except:
		return False


p = {'ip':'node001','port':15004}
print checkConnection(p)

